<template>
</template>

<script>
import waves from '@/directive/waves'
import Pagination from '@/components/Pagination/index.vue'
import {
  checkAuthCode,
  isDebugMode, notifySuccess,
  showDictKeyLabel,
  showDictLabel,
  showEnumKeyLabel,
  showEnumLabel,
  showIdLabel, svc,
} from '@/config/common'
import useTableMaxHeightStore from '@/store/modules/tableMaxHeight'
import useEnumsStore from "@/store/modules/enums";
import useDictStore from "@/store/modules/dict";
import {InfoFilled, WarningFilled} from "@element-plus/icons-vue";
import {getCodeByName, getIconByName, getPathByName, getTitleByName} from "@/router";
import {doGet, doPost} from "@/config/http";

export default {
  name: 'baseConfig',
  components: {Pagination},
  directives: {waves},
  data() {
    return {
      isDebug: isDebugMode(),
      nameOfPermission: null,
      userFavorites: null,
    }
  },
  computed: {
    InfoFilled() {
      return InfoFilled
    },
    WarningFilled() {
      return WarningFilled
    },
    tableMaxHeight() {
      return useTableMaxHeightStore().tableMaxHeight
    },
    stateEnable() {
      return '1'
    },
    stateDisable() {
      return '0'
    },
  },
  created() {
  },
  methods: {
    checkAuthByCode(code) {
      return checkAuthCode(code)
    },
    getEnumList(enumType) {
      return useEnumsStore().getEnums(enumType)
    },
    getEnumKeyLabel(enumType, key) {
      return showEnumKeyLabel(enumType, key)
    },
    getEnumLabelByKey(enumType, key) {
      return showEnumLabel(enumType, key)
    },
    getDictList(dictType) {
      return useDictStore().getDicts(dictType)
    },
    getDictKeyLabel(dictType, key) {
      return showDictKeyLabel(dictType, key)
    },
    getDictLabelByKey(dictType, key) {
      return showDictLabel(dictType, key)
    },
    getIdLabel(items, id, field) {
      return showIdLabel(items, id, field)
    },
    goTargetByName(name, query, closeCurrent) {
      const path = getPathByName(name)
      if (closeCurrent) {
        this.$tab.closeOpenPage({path, query})
      } else {
        this.$tab.openPage({path, query})
      }
    },
    getTitleByName,
    getIconByName,
    getCodeByName,
    getPathByName,
    addFav() {
      let code = getCodeByName(this.nameOfPermission)
      let title = getTitleByName(this.nameOfPermission)
      let icon = getIconByName(this.nameOfPermission)
      let path = getPathByName(this.nameOfPermission)
      if (!code)
        return
      let data = {code, title, icon, name: this.nameOfPermission, path}
      doPost(svc, `/customUserFavorite/addFavorite`, data, false).then(() => {
        this.getFavorite(this.nameOfPermission).then(res => {
          this.userFavorites = res
          notifySuccess('收藏成功')
        })
      })
    },
    delFav() {
      let code = getCodeByName(this.nameOfPermission)
      if (!code)
        return
      doPost(svc, `/customUserFavorite/delFavorite/${code}`, {}, false).then(() => {
        this.getFavorite(this.nameOfPermission).then(res => {
          this.userFavorites = res
          notifySuccess('取消收藏成功')
        })
      })
    },
    getFavorite(name) {
      let code = getCodeByName(name)
      if (!code)
        return null
      return doGet(svc, `/customUserFavorite/getFavorite/${code}`, {}, false)
    },
  }
}
</script>
<style>
.el-input-number {
  width: 200px;
}
</style>
<style scoped>
</style>
